﻿/*
Copyright (c) 2009 Vratislav Cermak (vratacermak@gmail.com)
 
This file is part of TeachMe Project. See http://code.google.com/p/teach-me for more information.
 
TeachMe is an open source project. Using of TeachMe is free of charge.
It is distributed under GNU General Public License version 3 (GPLv3).
GPLv3 can be found at http://www.gnu.org/licenses/gpl.html.
 
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace TeachMe.Application.Controls
{
    public class TrackBarLabel : Label
    {
        private TrackBar _trackBar;
        private string _unit;

        [Localizable(true)]
        public string Unit
        {
            get
            {
                return _unit;
            }
            set
            {
                _unit = value;
            }
        }

        public TrackBar TrackBar
        {
            get
            {
                return _trackBar;
            }
            set
            {
                _trackBar = value;

                if (_trackBar != null)
                {
                    _trackBar.ValueChanged += OnTrackBarValueChanged;
                    UpdateText();
                }
            }
        }

        void OnTrackBarValueChanged(object sender, EventArgs e)
        {
            UpdateText();
        }

        public void UpdateText()
        {
            Text = _trackBar.Value + (String.IsNullOrEmpty(_unit) ? String.Empty : String.Format(" {0}", _unit));
            Location = new Point(_trackBar.Location.X + _trackBar.Width, _trackBar.Location.Y + (_trackBar.Height) / 2 - (Height / 2) - 2);
        }
    }
}
